package com.bsoft.controller.JSON;

import com.bsoft.Exception.CommonException;
import com.bsoft.service.RegisterService;
import com.bsoft.utils.JSONUtil;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * description: 该接口实现预约挂号
 * create time:  17:15
 * 心电系统 EcgController
 * @author
 */
@Controller
@RequestMapping(value = "JSON/HIHIS/register")
public class RegisterController {
    private static Logger logger = LoggerFactory.getLogger(RegisterController.class);
    @Autowired
    private RegisterService registerService;

    @Autowired
    private  ApplicationEventPublisher eventPublisher;


    /**
     * 查询挂号科室信息
     *
     * @param req
     * @return
     * @throws CommonException
     */
    @RequestMapping(value = "listDepartment", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String listDepartment(@RequestBody Map<String, Object> req) throws CommonException {
        logger.info("查询科室传入参数：" + req);
        String res = registerService.listDepartment(req);
        logger.info("查询科室传出参数：" + res);
        return res;
    }


    @RequestMapping(value = "getBrdaList", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String getBrdaList(@RequestBody Map<String, Object> req) {
        logger.info("查询brxx传入参数：" + req);
        String brdaList = registerService.getBrdaList(req);
        logger.info("查询brxx传出参数：" + req);
        return brdaList;
    }

    /**
     * 权限
     */
    @RequestMapping(value = "getBrdaGHMX", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String getBrdaGHMX(@RequestBody Map<String, Object> req) {
        String brdaList = registerService.getBrdaGHMX(req);
        return brdaList;
    }


    @RequestMapping(value = "/hello", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String say(@RequestBody  Map<String,Object> req) throws Exception{
        String res = registerService.say(req);
        return res;
    }


    @RequestMapping(value = "/updateBRDA", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String updateBRDA(@RequestBody Map<String, Object> req) {
        String res = registerService.updateBRDA(req);
        return res;
    }


    @RequestMapping(value = "testTransactionManager", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String testTransactionManager(@RequestBody Map<String,Object> req){

        String res = registerService.testTransactionManager(req);
        return res;
    }


    /**开住院电子票:openHospitalTicket_YB 涉及医保的交易*/
    @RequestMapping(value = "openHospitalTicket_YB", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String openHospitalTicket_YB(@RequestBody Map<String,Object> req){
        logger.info("开住院电子票涉及医保:入参:"+ JSONUtil.map2Json(req));
        String res = registerService.openHospitalTicket_YB(req);
        logger.info("开住院电子票涉及医保:出参:"+ res);

        return res;
    }

    /**开住院电子票:openHospitalTicket 纯自费:不管本次开单的费用是否包含有医保可报销费用,但患者就坚持走纯自费*/
    @RequestMapping(value = "openHospitalTicket", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String openHospitalTicket(@RequestBody Map<String,Object> req){
        logger.info("开住院电子票纯自费:入参:"+ JSONUtil.map2Json(req));
        String res = registerService.openHospitalTicket(req);
        logger.info("开住院电子票纯自费:出参:"+ res);

        return res;
    }

    /**存储过程调用测试*/
    @RequestMapping(value = "storedProceduresTest", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String storedProceduresTest(@RequestBody Map<String,Object> req){
        logger.info("存储过程调用测试:入参:"+ JSONUtil.map2Json(req));
        String res = registerService.storedProceduresTest(req);
        logger.info("存储过程调用测试:出参:"+ res);

        return res;
    }

    @GetMapping("/patients")
    public String listPatients(Model model) {
        List<Map<String,Object>> patientsList = registerService.findAllPatients();
        model.addAttribute("patients", patientsList);
        return "patients"; // 返回的视图名称
    }


    /**HIHIS大区版聚合支付二维码获取*/
    @RequestMapping(value = "sbCompanyPay", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    @ResponseBody
    public void getSbCompanyPay(@Param("idVismed") String idVismed, @Param("acToken") String acToken, HttpServletResponse response)throws Exception{
        logger.info("HIHIS大区版聚合支付二维码获取:入参:idVismed:{}::acToken:{}",idVismed,acToken);
        registerService.getSbCompanyPay(idVismed,acToken,response);
        //logger.info("HIHIS大区版聚合支付二维码获取:出参:"+ res);
    }

}
